﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint.Portal.WebControls;

namespace ESF.SharePoint.Helpers.Utility
{
    class UserProfileHelper
    {
        public static UserProfile GetUserProfile()
        {
            return ProfileLoader.GetProfileLoader().GetUserProfile();
        }

        public static string GetUserPicture()
        {
            string PropertyName = "PictureUrl";
            
            ProfileManagerBase userProfileManager = null;
            ProfileBase userProfile = null;
            ProfileLoader profileLoader = ProfileLoader.GetProfileLoader();
            userProfileManager = profileLoader.GetUserProfileManager();
            userProfile = profileLoader.GetUserProfile();
            if ((userProfileManager == null) || (userProfile == null))
            {
                return null;
            }
            string smallThumbnailUrl = null;
            if (!string.IsNullOrEmpty(PropertyName))
            {
                ProfileValueCollectionBase profileValueCollection = userProfile.GetProfileValueCollection(PropertyName);
                if ((profileValueCollection != null))
                {
                    smallThumbnailUrl = (string)profileValueCollection.Value;
                }
            }
            if (string.IsNullOrEmpty(smallThumbnailUrl))
            {
                return ResourceFilePath.GetResourceFileUrl(ResourceFileContext.SharedImage, "O14_person_placeHolder_192.png");
            }
            else
            {
                return ESF.SharePoint.Utility.ESFUtility.GetLargeThumbnailUrl(smallThumbnailUrl);
            }
        }
        
    }
}
